package com.wisdom.smartbook.facelib.core.utils;

import android.content.Context;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;

public class FileUtils
{
    public static byte[] readLocalFile(final Context context, final String fileName) throws IOException {
        final InputStream inputStream = context.getAssets().open("models/" + fileName);
        final byte[] data = toByteArray(inputStream);
        inputStream.close();
        return data;
    }
    
    private static byte[] toByteArray(final InputStream in) throws IOException {
        final ByteArrayOutputStream out = new ByteArrayOutputStream();
        final byte[] buffer = new byte[4096];
        int n = 0;
        while ((n = in.read(buffer)) != -1) {
            out.write(buffer, 0, n);
        }
        return out.toByteArray();
    }
}
